package com.wuxiaoge;

import jakarta.servlet.ServletException;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.DispatcherServlet;

import java.io.IOException;

@Configuration
public class Application {

    public static void main(String[] args) throws ServletException, IOException {
        // 初始化 Spring 容器
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Application.class);

        // 获取 DispatcherServlet 实例
        DispatcherServlet dispatcherServlet = context.getBean(DispatcherServlet.class);

        // 配置 DispatcherServlet
        dispatcherServlet.setContextConfigLocation("com.example.config");
        dispatcherServlet.init();

        System.out.println("Spring Web Application started!");
    }

    @Bean
    public DispatcherServlet dispatcherServlet() {
        return new DispatcherServlet();
    }

}
